<?php

use Illuminate\Database\Eloquent\Builder;

function paginate( $list, $page = 1, $row = 10)
{

    $page=abs((int)$page);

    if(!$list) return ['currentPage'=>1,'data'=>[],'total'=>0];

    $count = clone $list;

    $total = $count->count();

    $offset = ($page - 1) * $row;

    $data = $list->offset($offset)->limit($row)->get();

    return ['currentPage'=>$page,'data'=>$data,'total'=>$total];

}


function groupByKey($array,$key,$defaultKey='其他'){

    $result=[];

    foreach ($array as $k=>$v){

        $item=$v[$key];

        if(!$item) $item=$defaultKey;

        $result[$item][]=$v;

    }

    return $result;
}
